
package edu.hit.irlab.coref.features.pair;

import java.util.List;

import nlpeap.ml.FeatureDescription;
import nlpeap.ml.FeatureType;

import edu.hit.irlab.coref.PairFeatureExtractor;
import edu.hit.irlab.coref.PairInstance;

/**
 * The Salience mention type features
 *
 * @author chuter
 */
public class FE_MentionType_Salience implements PairFeatureExtractor {
    
    public static final FeatureDescription<Boolean> FD_J_IS_PN=
            new FeatureDescription<Boolean>(FeatureType.FT_BOOL, "anaIsPN");
   public static final FeatureDescription<Boolean> FD_J_IS_DEMONSTRATIVE=
            new FeatureDescription<Boolean>(FeatureType.FT_BOOL, "anaIsDemonstrative");
    public static final FeatureDescription<Boolean> FD_J_IS_DEM_NOMINAL=
            new FeatureDescription<Boolean>(FeatureType.FT_BOOL, "anaIsDemNominal");
    public static final FeatureDescription<Boolean> FD_J_IS_DEM_PRONOUN=
            new FeatureDescription<Boolean>(FeatureType.FT_BOOL, "anaIsDemPronoun");
    public static final FeatureDescription<Boolean> FD_J_IS_PRONOUN=
            new FeatureDescription<Boolean>(FeatureType.FT_BOOL, "anaIsPronoun");
    public static final FeatureDescription<Boolean> FD_J_IS_PERS_PRONOUN=
            new FeatureDescription<Boolean>(FeatureType.FT_BOOL, "anaIsPersPronoun");
    public static final FeatureDescription<Boolean> FD_I_IS_PRONOUN=
            new FeatureDescription<Boolean>(FeatureType.FT_BOOL, "antIsPronoun");
    //Both-Proper-Name Feature from soon
    public static final FeatureDescription<Boolean> FD_ARE_PROPERNAMES=
            new FeatureDescription<Boolean>(FeatureType.FT_BOOL, "areProperName");

    public void describeFeatures(List<FeatureDescription> fds) {
        fds.add(FD_J_IS_PN);
        fds.add(FD_J_IS_DEMONSTRATIVE);
        fds.add(FD_J_IS_DEM_NOMINAL);
        fds.add(FD_J_IS_DEM_PRONOUN);
        fds.add(FD_J_IS_PRONOUN);
        fds.add(FD_J_IS_PERS_PRONOUN);
        // two extra features for 2.9b
        //fds.add(FD_I_IS_PN);
        //fds.add(FD_I_IS_DEFINITE);
        fds.add(FD_I_IS_PRONOUN);
        fds.add(FD_ARE_PROPERNAMES);
    }
    
    /*  Extract features from mention and stores them in instance */
    public void extractFeatures(PairInstance inst) {
        // anaphor
        inst.setFeature(FD_J_IS_PN,inst.getAnaphor().getProperName());
        inst.setFeature(FD_J_IS_DEMONSTRATIVE,inst.getAnaphor().getDemonstrative()); 
        inst.setFeature(FD_J_IS_DEM_NOMINAL,inst.getAnaphor().getDemNominal()); 
        inst.setFeature(FD_J_IS_DEM_PRONOUN,inst.getAnaphor().getDemNoun()); 
        inst.setFeature(FD_J_IS_PRONOUN, inst.getAnaphor().getPronoun());  
        inst.setFeature(FD_J_IS_PERS_PRONOUN, inst.getAnaphor().getPerProNoun());      
        
        // ante
        inst.setFeature(FD_I_IS_PRONOUN, inst.getAntecedent().getPronoun());
        inst.setFeature(FD_ARE_PROPERNAMES, areBothProperNames(inst));
    }
    
    private Boolean areBothProperNames(PairInstance inst)
    {
        return (
                inst.getAntecedent().getProperName()
             &&
                inst.getAnaphor().getProperName()
        );
    }
    
}
